    //
//  CustomUISplitViewController.m
//  MasterDetail
//
//  Created by Andreas Katzian on 15.05.10.
//  Copyright 2010 Blackwhale GmbH. All rights reserved.
//

 



#import "CustomUISplitViewController.h"
#import "AppDelegate.h"

@implementation CustomUISplitViewController

@synthesize  AppleDeglate  ;


#pragma mark -
#pragma mark  畫面選轉事件 並觸動重新繪圖事件

 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    
    
    // Overriden to allow any orientation.
    //如果是iPad 則需要處理旋轉
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        //1.傳遞目前的方向 存到AppleDeglate        
        if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft) {
            NSLog(@"UIInterfaceOrientationLandscapeLeft 水平 Left");
            NSLog(@"主圖消失");
            
            [[(AppDelegate * )AppleDeglate Master_popController]  dismissPopoverAnimated:YES];
            
            [(AppDelegate * )AppleDeglate Get_interfaceOrientation:@"UIInterfaceOrientationLandscapeLeft 水平"];         
               
        }else if(interfaceOrientation==UIInterfaceOrientationLandscapeRight){
            NSLog(@"UIInterfaceOrientationLandscapeRight 水平 Right");
            NSLog(@"主圖消失");
            [[(AppDelegate * )AppleDeglate Master_popController]  dismissPopoverAnimated:YES];             
            [(AppDelegate * )AppleDeglate Get_interfaceOrientation:@"UIInterfaceOrientationLandscapeRight 水平"]; 
            
            
                  
        }else if( interfaceOrientation==UIInterfaceOrientationPortrait ){
            NSLog(@"UIInterfaceOrientationPortrait 垂直");
            [(AppDelegate * )AppleDeglate Get_interfaceOrientation:@"UIInterfaceOrientationPortrait 垂直"];     
                    
        }else if(interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown){
            NSLog(@"UIInterfaceOrientationPortraitUpsideDown 垂直");
            [(AppDelegate * )AppleDeglate Get_interfaceOrientation:@"UIInterfaceOrientationPortraitUpsideDown 垂直"];     
            
            
        }             
     
        
           
        
        
        
        //2.觸動繪圖事件 將畫布大小重新調整
        if ( [(AppDelegate * )AppleDeglate agraph]  )  {
            
            // [ [(AppDelegate * )AppleDeglate agraph] loadView];
             [ [(AppDelegate * )AppleDeglate agraph] viewDidLoad];
             [ [(AppDelegate * )AppleDeglate agraph] redrawChart:YES];
      
        
             if ([[(AppDelegate * )AppleDeglate popController_info ] isPopoverVisible]==YES   ) {
                 
                 [[(AppDelegate * )AppleDeglate popController_info ] dismissPopoverAnimated:YES];
                              
             }   
            if ([[(AppDelegate * )AppleDeglate popController_info_next ] isPopoverVisible]==YES   ) {
                NSLog(@"yeee"); 
                [[(AppDelegate * )AppleDeglate popController_info_next ] dismissPopoverAnimated:YES];  
            } 
            else{
              NSLog(@"noo");
            }
          
            
        }
        
        //標記:利用此方法可以讓畫面一開始就是橫躺  不過此方法無法通過App Store 審核    
        // return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
       
        //help
        
          [[(AppDelegate * )AppleDeglate ahelp] resizeframe];        
             
        return  YES;        
    }
    else{
        return  YES;
    }
    
}

- (BOOL)shouldAutorotate {
   UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation]; 
    
    
    NSLog(@"aaaaaccc w=%f h=%f",[[[(AppDelegate * )AppleDeglate dv] view] bounds].size.width,[[[(AppDelegate * )AppleDeglate dv] view] bounds].size.height);
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        //1.傳遞目前的方向 存到AppleDeglate
        if (orientation==UIInterfaceOrientationLandscapeLeft) {
            NSLog(@"UIInterfaceOrientationLandscapeLeft 水平 Left");
            NSLog(@"主圖消失");
            [[(AppDelegate * )AppleDeglate Master_popController]  dismissPopoverAnimated:YES];
            
            [(AppDelegate * )AppleDeglate Get_interfaceOrientation:@"UIInterfaceOrientationLandscapeLeft 水平"];
            
        }else if(orientation==UIInterfaceOrientationLandscapeRight){
            NSLog(@"UIInterfaceOrientationLandscapeRight 水平 Right");
            NSLog(@"主圖消失");
            [[(AppDelegate * )AppleDeglate Master_popController]  dismissPopoverAnimated:YES];
            [(AppDelegate * )AppleDeglate Get_interfaceOrientation:@"UIInterfaceOrientationLandscapeRight 水平"];
            
            
            
        }else if( orientation==UIInterfaceOrientationPortrait ){
            NSLog(@"UIInterfaceOrientationPortrait 垂直");
            [(AppDelegate * )AppleDeglate Get_interfaceOrientation:@"UIInterfaceOrientationPortrait 垂直"];
            
        }else if(orientation==UIInterfaceOrientationPortraitUpsideDown){
            NSLog(@"UIInterfaceOrientationPortraitUpsideDown 垂直");
            [(AppDelegate * )AppleDeglate Get_interfaceOrientation:@"UIInterfaceOrientationPortraitUpsideDown 垂直"];
            
            
        }
        
        
        
        
        
        
        //2.觸動繪圖事件 將畫布大小重新調整
        if ( [(AppDelegate * )AppleDeglate agraph]  )  {
            
            // [ [(AppDelegate * )AppleDeglate agraph] loadView];
            
            
            
            if ([[(AppDelegate * )AppleDeglate popController_info ] isPopoverVisible]==YES   ) {
                
                [[(AppDelegate * )AppleDeglate popController_info ] dismissPopoverAnimated:YES];
                
            }
            if ([[(AppDelegate * )AppleDeglate popController_info_next ] isPopoverVisible]==YES   ) {
                 
                [[(AppDelegate * )AppleDeglate popController_info_next ] dismissPopoverAnimated:YES];
            }
            else{
                
            }
            
            [[(AppDelegate * )AppleDeglate agraph] resize_graph_frame ];
            
        }
        
        //標記:利用此方法可以讓畫面一開始就是橫躺  不過此方法無法通過App Store 審核
        // return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
        
        //help
        
        [[(AppDelegate * )AppleDeglate ahelp] resizeframe];
        
        return  YES;
    }
    
    
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}
 
 

- (void)dealloc {
    [super dealloc];
}


@end
